package org.example.multi;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.Transaction;

public class trans {
    public static void main(String[] args) {
        Jedis jedis = new Jedis("127.0.0.1", 6379);
        jedis.flushDB();
        //开启事务
        Transaction mutils = jedis.multi();
        try {
            mutils.set("userkk","cc");
            mutils.set("userkk2","cc");
            int i = 100/0;
            mutils.exec();
        }catch (Exception e){
            e.printStackTrace();
            //如果出现异常，回滚
            mutils.discard();
        }finally{
            System.out.println(jedis.get("userkk"));
            System.out.println(jedis.get("userkk2"));
            //最终关闭客户端
            jedis.close();
        }

    }
}
